<template>
  <div class="box">
    <el-form
      :model="ruleForm"
      :inline="false"
      ref="ruleForm"
      :rules="rules"
      label-width="200px"
      class="demo-ruleForm"
      size="medium"
    >
      <!-- <h2 class="tle">业务申请信息填写</h2> -->
      <div class="must">
        <div class="cad">
          <!--<el-form-item label="联系人：" prop="linkman">-->
          <!--<el-input v-model="ruleForm.linkman" placeholder="请填写联系人"></el-input>-->
          <!--<div class="informm">-->
          <!--<img src="../../assets/imgs/inform.png" alt="通知" />-->
          <!--<div class="content">-->
          <!--<span>示例：王五</span>-->
          <!--</div>-->
          <!--</div>-->
          <!--</el-form-item>-->
          <!-- <el-form-item label="代理机构名称：">
                    <el-input v-model="ruleForm.institution" placeholder="请填写代理机构名称"></el-input>
          </el-form-item>-->
          <el-form-item label="商标注册号：" prop="number">
            <el-input v-model="ruleForm.number" placeholder="请填写商标注册号"></el-input>
            <div class="informm">
              <img src="../../assets/imgs/inform.png" alt="通知" />
              <div class="content">
                <span>示例：254515444</span>
              </div>
            </div>
          </el-form-item>
          <el-form-item label="是否共有商标：">
            <span id="star">*</span>
            <el-radio v-model="ruleForm.radio" :label="1">是</el-radio>
            <el-radio v-model="ruleForm.radio" :label="0">否</el-radio>
          </el-form-item>
          <el-form-item label="其他共有申请人：" v-if="ruleForm.radio">
            <both
              :callback="getBoth"
              :append="$store.state.alterData.append"
              :class_id="$route.query.id"
            ></both>
          </el-form-item>
          <!--<div v-if="ruleForm.radio" class="common">-->
          <!--<el-form-item label="其他共有人" prop="person_type"></el-form-item>-->
          <!--<div v-for="(item,index) in common" :key="index">-->
          <!--<el-form-item :label="item.name" prop="person_type">-->
          <!--<el-input v-model="item.value" placeholder="请填写姓名"></el-input>-->
          <!--</el-form-item>-->
          <!--<el-form-item :label="item.englishName" prop="person_type">-->
          <!--<el-input v-model="item.englishValue" placeholder="请填写姓名"></el-input>-->
          <!--</el-form-item>-->
          <!--<el-form-item :label="item.site" prop="person_site">-->
          <!--<el-input v-model="item.siteValue" placeholder="请填写地址"></el-input>-->
          <!--</el-form-item>-->
          <!--<el-form-item :label="item.englishSite" prop="person_site">-->
          <!--<el-input v-model="item.englishSiteValue" placeholder="请填写地址"></el-input>-->
          <!--</el-form-item>-->
          <!--</div>-->
          <!--<el-button icon="el-icon-plus" @click="plus" circle></el-button>-->
          <!--<el-button icon="el-icon-minus" @click="dele" v-if="common.length>0" circle></el-button>-->
          <!--</div>-->
          <el-form-item label="原续展申请号：" prop="oldnum">
            <el-input v-model="ruleForm.oldnum" placeholder="请填写原续展申请号"></el-input>
            <div class="informm">
              <img src="../../assets/imgs/inform.png" alt="通知" />
              <div class="content">
                <span>示例：125646454</span>
              </div>
            </div>
          </el-form-item>
          <el-form-item label="撤回理由：" prop="reason">
            <el-input type="textarea" v-model="ruleForm.reason" placeholder="请填写撤回理由"></el-input>
            <div class="informm">
              <img src="../../assets/imgs/inform.png" alt="通知" />
              <div class="content">
                <span>提示：撤回商标申请的理由</span>
              </div>
            </div>
          </el-form-item>
          <el-form-item class="upload" label="网上确认书：" prop="qrfile">
            <span id="staz">*</span>
            <img :src="echoImg" v-if="mark" style="width:148px;height:148px" />
            <upfile :callback="setSure"></upfile>
            <div class="exam-img">
              <div class="img-inform">
                <img src="../../assets/imgs/inform.png" />
                <span>示例:</span>
              </div>
              <examimg :imgType="7"></examimg>
            </div>
            <div>
              <span class="informs">
                请点此
                <a :href="mconfig.host + '/file/download?fileType=4'">下载网上确认书</a>,查到相应商标编号并填充
              </span>
              <br />
              <span class="notice">请将下载的网上确认书填写完成, 然后上传JPG文件或是PNG文件</span>
            </div>
          </el-form-item>
          <!-- 添加其他有效证件 -->
          <el-form-item label="其他附件：" prop="dengjichenluofile">
            <uploads
              :callback="backUrl"
              :delUrl="delUrl"
              :file_config="{field:'dengjichenluofile'}"
              :list="ruleForm.dengjichenluofile"
            ></uploads>
            <div class="img-inform">
              <img src="../../assets/imgs/inform.png" alt="通知" />
              <div class="content">
                <span>提示：其他附件</span>
              </div>
            </div>
          </el-form-item>

          <!-- next下一步 -->
          <el-form-item>
            <div class="btns">
              <el-button type="primary" @click="outStep">上一步</el-button>
              <el-button type="primary" @click="dialogVisible = true;verify('ruleForm')">提交并审核</el-button>
            </div>
          </el-form-item>
        </div>
        <el-dialog
          class="dialog"
          :show-close="false"
          :center="true"
          :visible.sync="dialogVisible"
          width="460px"
          :before-close="handleClose"
        >
          <div class="hint">
            <img src="../../assets/imgs/branch.png" alt="提示图片" />
            <span>选择您想去办理的网点</span>
          </div>
          <el-form-item label="选择网点：" prop="value">
            <el-select v-model="ruleForm.value" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptId"
              >
                <span style="float: left">{{ item.deptName }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.address }}</span>
              </el-option>
            </el-select>
          </el-form-item>
          <div slot="footer" class="dialog-footer">
            <el-button type="info" @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
          </div>
        </el-dialog>
        <el-dialog
          class="hintMsg"
          :show-close="false"
          title="温馨提示"
          :visible.sync="centerDialogVisible"
          width="462px"
        >
          <span>您的信息已提交，工作人员将在3-5日内对你的信息审核，审核通过后即可预约业务，审核结果将通过短信的方式发送给你。</span>
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="skip">确 定</el-button>
          </span>
        </el-dialog>
      </div>
    </el-form>
  </div>
</template>
<script>
import BaseUpload from "./BaseUpload";
import upfile from "../common/upfile.vue";
import both from "../common/both.vue";
import examimg from "../common/imgExample";
import uploads from "../common/uploads";
export default {
  components: {
    BaseUpload,
    upfile,
    both,
    examimg,
    uploads
  },
  data() {
    return {
      // 回显图片
      echoImg: "",
      //  控制图片的显
      reveal: "",
      //网点列表
      options: [],
      //提交成功弹出框变量
      centerDialogVisible: false,
      //网点弹出框控制变量
      dialogVisible: false,
      //表单唯一id
      classId: "",
      //共有人
      common: [],
      //共有人模板
      commonModel: {
        name: "更变前名称(中文)：",
        englishName: "(英文)：",
        site: "变更前地址(中文)：",
        englishSite: "(英文)：",
        value: "",
        englishValue: "",
        siteValue: "",
        englishSiteValue: "",
      },
      //实际模板
      modelcommon: {
        partNameCh: "",
        partNameEn: "",
        partAddrCh: "",
        partAddrEn: "",
      },
      //填写的信息
      ruleForm: {
        // userId: 2,
        //        linkman: "",
        institution: "",
        number: "",
        oldnum: "",
        radio: 0,
        reason: "",
        value: "",
        type: "",
        qrfile: "", // 网上确认书
        commonArr: [],
        dengjichenluofile:[],
      },
      imgfile: "",
      rules: {
        //        linkman: [
        //          { required: true, message: "联系人不能为空", trigger: "blur" },
        //          {
        //            pattern: /^[\u0391-\uFFE5]{2,30}$/,
        //            message: "请输入正确的名称",
        //            trigger: "blur",
        //          },
        //        ], //  联系人
        number: [
          {
            required: true,
            message: "请输入商标注册号",
            trigger: "blur",
          },
          {
            pattern: /^[A-Za-z0-9]{0,30}$/,
            message: "请输入正确的商标注册号",
            trigger: "blur",
          },
        ], //  请传入其他附件
        // dengjichenluofile:[{required: true,
        //     message: "请传入其他附件",
        //     trigger: "blur",}],
         //  申请号
        oldnum: [
          // {
          //     required: true,
          //     message: "原续展申请号不能为空",
          //     trigger: "blur",
          // },
          // {
          //     pattern: /^[0-9]{7,15}$/,
          //     message: "请输入正确原续展申请号",
          //     trigger: "blur",
          // },
          {
            required: true,
            message: "请输入申请号",
            trigger: "blur",
          },
          {
            pattern: /^[A-Za-z0-9]{0,30}$/,
            message: "请输入正确的申请号",
            trigger: "blur",
          },
        ], //  变更管理规则
        reason: [
          {
            required: true,
            message: "撤回理由不能为空不能为空",
            trigger: "blur",
          },
        ], //  变更管理规则
        // qrfile: [
        //     {required: true, message: "网上确认书不能为空", trigger: "blur"},
        // ], //  网上确认书
      },
      mark: false, //  确认书的标记
    };
  },
  mounted() {
    //获取从存储在路由中的classId
    this.classId = this.$route.query.id;
    //获取网点列表
    this.$http.get("/trademark/system/dept/findDept").then((res) => {
      this.options = res.data.data;
    });
    //修改申请信息的数据回显（第三那部分）
    if (this.$store.state.stateJdg) {
      this.mark = true;
      //console.log(this.$store.state.alterData);
      // this.$store.state.alterData.public.qrfile;
      //      this.ruleForm.linkman = this.$store.state.alterData.data.contacts; //  联系人
      //      this.ruleForm.institution = this.$store.state.alterData.data.agent; //  代理机构名称
      this.ruleForm.number = this.$store.state.alterData.data.registNum; //  商标注册号
      this.ruleForm.radio = parseFloat(
        this.$store.state.alterData.data.isShare
      ); //  是否共有商标
      this.ruleForm.common = this.$store.state.alterData.append; //  其他共有人

      this.ruleForm.reason = this.$store.state.alterData.data.reasonsWithdrawal; //  撤回理由
      this.ruleForm.oldnum = this.$store.state.alterData.data.registNumOri; //  原续展申请号
      this.ruleForm.qrfile = {}; // 确认证书(添加修改)
  //其他附件
      this.ruleForm['dengjichenluofile'] =JSON.parse(this.$store.state.alterData.otherfile);
          
 
      this.echoImg =
        this.mconfig.host + this.$store.state.alterData.public.qrfile; // 确认证书（页面回显）
    
      for (var s = 0; s < this.$store.state.alterData.append.length; s++) {
        //  共享人信息的赋值
        this.common[s] = {};
        this.$set(this.common, s, {
          name: "更变前名称(中文)：",
          englishName: "(英文)：",
          site: "更变前地址(中文)：",
          englishSite: "(英文)：",
          value: this.$store.state.alterData.append[s].partAddrCh,
          englishValue: this.$store.state.alterData.append[s].partAddrEn,
          siteValue: this.$store.state.alterData.append[s].partNameCh,
          englishSiteValue: this.$store.state.alterData.append[s].partNameEn,
        });
        this.plus();
      }
      this.common.splice(s, 1);
      this.ruleForm.commonArr.splice(s, 1);
      this.reveal = this.$store.state.stateJdg;
    }
  },
  watch: {
    //通过数据监听的方式将共有人模板中的信息同步到ruleForm.commonArr中
    common: {
      handler(newName, oldName) {
        //                    this.common.forEach((item, index) => {
        //                        this.ruleForm.commonArr[index].partNameCh = item.value;
        //                        this.ruleForm.commonArr[index].partNameEn = item.englishValue;
        //                        this.ruleForm.commonArr[index].partAddrCh = item.siteValue;
        //                        this.ruleForm.commonArr[index].partAddrEn = item.englishSiteValue;
        //                    });
      },
      deep: true,
    },
    //  监听判断是否执行新增变更人
    "ruleForm.radio": function (val) {
      if (val == 1) {
        if (this.$store.state.stateJdg == false) {
          this.plus();
        }
      } else {
        this.dele();
      }
    },
  },
  methods: {
    getBoth(value) {
      this.ruleForm.commonArr = JSON.parse(JSON.stringify(value));
      this.common = JSON.parse(JSON.stringify(value));
    },
    //   确认书
    setSure(files) {
      this.ruleForm.qrfile = files[0];
      this.mark = false;

    },
//其他证件
    backUrl(url, file_config) {
      this.ruleForm[file_config["field"]].push(url);
    },
     delUrl(index,file_config){
          this.ruleForm[file_config["field"]].splice(index,1)
          this.$set(this.ruleForm,file_config["field"],this.ruleForm[file_config["field"]])
      },

    //返回上一步
    outStep() {
      this.$emit("wp", 1, "请填写申请业务信息");
    },

    //弹出框的选项确认框
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    //点击添加更变许可人
    plus() {
      let objCommom = JSON.parse(JSON.stringify(this.modelcommon));
      this.ruleForm.commonArr.push(objCommom);
      let objValue = JSON.parse(JSON.stringify(this.commonModel));
      this.common.push(objValue);
      console.log(this.common);
    },
    //点击删除
    dele() {
      this.common.pop();
      this.ruleForm.commonArr.pop();

      if (this.common.length == 0) {
        this.ruleForm.radio = 0;
      }
    },
    //提示模板
    open1(msg, types = "success") {
      this.$message({
        message: msg,
        type: types,
      });
      //  console.log(msg)
    },
    //验证规则
    verify(formName) {
      let status = true;
      let inside = true;

      this.$refs[formName].validate((valid) => {
        if (valid) {
        } else {
          this.open1("请完整填写表单数据", 66);
          this.dialogVisible = false;
          status = false;
          return false;
        }
      });
      //                if (status !== false) {
      //                    this.ruleForm.commonArr.forEach((item) => {
      //                        if (inside == true) {
      //                            if (item.partAddrCh == "" || item.partNameCh == "") {
      //                                this.open1("更变前名称(中文)或更变前地址(中文) 不能为空", 11);
      //                                this.dialogVisible = false;
      //                                inside = false;
      //                            }
      //                        }
      //                    });
      //                }

      if (this.ruleForm.qrfile == "" && this.$store.state.stateJdg == true) {
        this.ruleForm.qrfile = {}; //   原商品确认书不变赋值
        // console.log(this.ruleForm.qrfile);
      }
    },

    //表单提交事件
    submitForm(formName) {
      let _this = this;
      if (this.ruleForm.value == "") {
        return this.open1("请选择网点", 55);
      }
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //每次提交重新生成新的FormData用于储存新的数据
          var formData = new FormData();
          this.dialogVisible = false;
          let arr = this.$store.getters.getRuleForm;
          for (let key in arr) {
            formData.append(key, arr[key]);
          }
          //我的
          if (this.$store.state.stateJdg == false) {
            formData.append("optype", 0); //   操作类型（0保存，1调整）
          } else {
            formData.append("optype", 1);
            formData.append("id", this.$store.state.alterData.public.id); //   id号
            formData.append(
              "modelId",
              this.$store.state.alterData.public.modelId
            ); //   modelid的传递
          }
          formData.append("classId", this.classId);
          //          formData.append("contacts", this.ruleForm.linkman); //  联系人
          //          formData.append("agent", this.ruleForm.institution); //  代理机构名称
          formData.append("registNum", this.ruleForm.number); //  商标注册号
          formData.append("registNumOri", this.ruleForm.oldnum); //  原续展申请号
          formData.append("isShare", this.ruleForm.radio); //  是否共有商标
          formData.append("reasonsWithdrawal", this.ruleForm.reason); //  撤回理由
          formData.append("qrfiles", this.ruleForm.qrfile); //    网上确认书
           formData.append("otherfile", JSON.stringify(this.ruleForm.dengjichenluofile)); //    其他附件
          formData.append(
            //   共有人
            "proAppends",
            JSON.stringify(this.ruleForm.commonArr)
          );
          formData.append("branchNetworkId", this.ruleForm.value); //   网点编号
          //配置请求头
          var config = {
            header: {
              "Content-Type": "multipart/form-data",
            },
          };
          this.$http
            .post(
              this.$store.state.stateJdg
                ? "/trademark/proWotlrf/modifyNoCommit"
                : "/trademark/proWotlrf/firstSubmit",
              formData,
              config
            )
            .then(function (response) {
              //若状态码不为200则不跳转
              if (response.data.code != 200) {
                _this.open1("提交失败", "error");
                return;
              }

              _this.centerDialogVisible = true;
            })
            .catch(function (error) {});
        } else {
          return false;
        }
      });
      this.echoImg = false;
    },
    //跳转函数
    skip() {
      this.centerDialogVisible = false;
      this.open1("操作成功");
      this.$router.push({
        path: "/business/myBusiness/auditing",
      });
    },
    //重置表单函数(没用上)
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="less" scoped>
//  修改的表单样式
.el-textarea {
  width: 80%;
}

.box .upload[data-v-4feac3cb] {
  margin: 15px 0 20px 0;
  margin-left: -15%;
}

.upload .el-form-item__content div:nth-of-type(1) {
  margin-top: 10px;
}

.cad .el-form-item {
  margin-left: -15%;
}

.cad .el-input {
  width: 80%;
}

.informm {
  display: flex;
  align-items: center;
  position: absolute;
  top: 0;
  left: 100%;
  width: 250px;
  height: 32px;
  color: #f96900;
  font-size: 10px;
  line-height: 14px;
  margin-left: -20%;
  img {
    margin: 11px;
  }
  .content {
    display: flex;
    flex-direction: column;
    .ts {
      text-indent: 3em;
    }
  }
}

.btns {
  display: flex;
  justify-content: center;
  .el-button {
    margin: 0 20px;
  }
}

.box {
  display: flex;
  padding-right: 112px;
  flex-direction: column;
  align-items: center;
  // margin-top: 100px;
  width: 100%;
  min-height: 800px;
  .tle {
    font-size: 24px;
    color: #000;
  }
  .must,
  .select {
    display: flex;
    position: relative;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 0 30px;
    margin-bottom: 80px;
    // width: 1000px;
    // border: 1px solid #bbbbbb;
    border-radius: 10px;
    .el-form-item {
      width: 680px;
    }
    .inline {
      display: flex;
      .el-form-item {
        margin: 0;
        width: 290px !important;
      }
    }
  }
  .must {
    margin-bottom: 20px;
  }
  .line {
    width: calc(100% - 280px);
    margin: 10px auto;
    height: 1px;
    border-top: 1px dashed #d9d9d9;
  }
  .imgHint {
    margin: 5px;
    font-size: 12px;
    line-height: 17px;
    color: #f5222d;
  }
  .affirm {
    font-size: 12px;
    color: #a0a3a5;
    a {
      text-decoration: none;
      color: #3685ff;
    }
  }
  .input {
    width: 190px;
  }
  .upload {
    margin: 20px 0;
  }
  .type-number {
    width: 250px;
  }
  .informs {
    position: absolute;
    width: 500px;
    font-size: 12px;
    color: #a0a3a5;
    a {
      text-decoration: none;
      color: #3685ff;
    }
  }
  .notice {
    color: #f00;
    font-size: 12px;
  }
  .tle {
    list-style: none;
    margin: 40px 0 20px;
    font-size: 24px;
    & ~ .tle {
      color: #bbb;
    }
  }
  .hint {
    color: #f5222d;
    background-color: #fff;
    .el-form-item__label {
      width: 150px;
    }
    img {
      width: 20px;
    }
  }
  .el-steps {
    width: 70%;
    height: 200px;
  }
  .el-button {
    //display: block;
    display: inline;
    margin: 0 20px;
    // background-color: #67c23a !important;
    // border-color: #67c23a !important;
  }

  .common .el-button {
    margin-bottom: 10px;
    background-color: #fff !important;
    border-color: #bbb !important;
  }
}

.dialog-footer {
  display: flex;
  justify-content: space-between;
  color: #fff;
  .lan {
    background-color: #2c9dfc !important;
    border-color: #2c9dfc !important;
  }
}

.dialog /deep/ .el-form-item__label {
  width: 100px !important;
}

.dialog /deep/ .el-form-item__content {
  margin-left: 100px !important;
  display: flex;
  justify-content: left;
}

.dialog /deep/ .el-input {
  width: 250px;
}

.el-checkbox-group {
  line-height: 14px;
}

.is-checked /deep/ .el-radio__inner,
.is-checked /deep/ .el-checkbox__inner {
  border-color: #409eff;
  background: #409eff;
}

.el-radio /deep/ .el-radio__inner:hover {
  border-color: #999999 !important;
}

.is-checked /deep/ .el-radio__label,
.is-checked /deep/ .el-checkbox__label {
  color: #333;
}

.is-focus .el-checkbox__inner {
  border-color: #999999 !important;
}

.el-checkbox /deep/ .el-checkbox__inner:hover {
  border-color: #999999 !important;
}

.el-step__head.is-process {
  border-color: #f96900;
  color: #f96900 !important;
}

.hintMsg {
  /deep/ .el-dialog__header {
    display: flex;
    justify-content: center;
    font-weight: bold;
  }
  .dialog-footer {
    justify-content: center;
    .el-button {
      border-color: #2c9dfc !important;
      background: #2c9dfc !important;
    }
  }
}
#star {
  position: absolute;
  color: red;
  margin-left: -120px;
}
#staz {
  position: absolute;
  color: red;
  margin-left: -105px;
}
.exam-img{
  position: absolute;
  top: 0;
  left: 465px;
}
.img-inform{
  img{
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -140px;
    transform: translate(-50%,-50%);
  }
  span{
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
      white-space: nowrap;
      margin-left: -100px;
      width: 50px;
      color: #f96900;
  }
}
.content{
    width: 100%;
    margin: 0px;
    // margin-left: 30px;
    padding: 0px;
}
</style>